package TUILayer;
import java.util.Scanner;
import ControlLayer.*;

/**
 * 
 * @Author (Alexander Hvidberg, Dennis Kirkebak & Thomas Kulmbach)
 * @Team (Group 1)
 * @Version (08/11/13)
 * 
 */
public class RentalUI
{
    // instance variables - replace the example below with your own
    private RentalCtr rentCtr;

    /**
     * Constructor for objects of class RentalUI
     */
    public RentalUI()
    {
       rentCtr = RentalCtr.getInstance();
    }
    
    public void start()
    {
        rentalMenu();
    }

    public void rentalMenu()
    {
        boolean exit = false;
            while(!exit)
            {
                int choise = writeRentalMenu();
                if(choise == 1)
                {
                    createRental();
                   }
          else{
              if(choise == 2){
                    deleteRental();
              }  
              else{
                  if(choise == 3){
                      findRental();
                  }  
                  else{
                      if(choise == 4){
                          printRentalList();
                      }
                      else{
                          if(choise == 5){
                             clearScreen();
                            }
                                else{
                              exit = true;
                           }//end else
                        }//end else
                    }//end else
                }//end else
        }//end else
            
       }//end while
    }
    private int writeRentalMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\n\n *** Rental Menu ***");
        System.out.println(" (1) Add rental");
        System.out.println(" (2) Delete rental");
        System.out.println(" (3) Find rental");
        System.out.println(" (4) Print list of rentals");
        System.out.println(" (5) Clear Screen");
        System.out.println(" (6) Return");
        System.out.println("\n Make your choice: ");
    
        int choise = keyboard.nextInt();
        return choise;
            
            
    }
    
      /**
     * A method to record an input of the persons ID
     * @return int id - The persons ID number
     */
    private int inputRentalID()
    {   
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
            // makes an object keyboard to have input from the console
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Write rental Id:  ");
                try{
                    id = keyboard.nextInt();
                    ok = true;
                }
                catch (Exception e)
                {
                    System.out.println("The input must be a number - Try again");
                    String input = keyboard.nextLine();
                }
        }//end while
        return id;
    }

       /**
     * A method to record an input of the persons ID
     * @return int id - The persons ID number
     */
    private int inputDVDID()
    {   
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
            // makes an object keyboard to have input from the console
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Write DVD Id:  ");
                try{
                    id = keyboard.nextInt();
                    ok = true;
                }
                catch (Exception e)
                {
                    System.out.println("The input must be a number - Try again");
                    String input = keyboard.nextLine();
                }
        }//end while
        return id;
    }
    private String inputPhone()
    {
         // makes an object keyboard to have input from the screen
         Scanner keyboard = new Scanner(System.in);  
         System.out.println(" Write Phone Number:  ");
         String phone = keyboard.nextLine();
         return phone;
    } 
    
    private String inputRentalDate()
    {
         // makes an object keyboard to have input from the screen
         Scanner keyboard = new Scanner(System.in);  
         System.out.println(" Write Rental Date:  ");
         String date = keyboard.nextLine();
         return date;
    }
    
    private int inputRentalPeriod()
    { 
        boolean ok = false;
        int period = 0;
        while(!ok)
        {
            // makes an object keyboard to have input from the console
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Write Rental Period:  ");
                try{
                    period = keyboard.nextInt();
                    ok = true;
                }
                catch (Exception e)
                {
                    System.out.println("The input must be a number - Try again");
                    String input = keyboard.nextLine();
                }
        }//end while
        return period;
    }
    
    private void findRental()
    {
        int id = inputRentalID();
        clearScreen();
        rentCtr.findRental(id);
    }
    
    private void clearScreen(){
        System.out.println("\f");
    }
 
    /*#
     * Der mangler tjek på om DVDer er ledige
     * 
     */
    private void createRental()
    {
        clearScreen();
        int id = inputDVDID();
        String phone = inputPhone();
        String date = inputRentalDate();
        int period = inputRentalPeriod();
        rentCtr.createRental(date, period, phone, id);
    }
    
    private void printRentalList(){
        clearScreen();
        rentCtr.printRentalList();
    }
    
    private void deleteRental(){
        int id = inputRentalID();
        rentCtr.deleteRental(id);
        
    }
}

  //Set & Get methods for the entire class

